﻿using System.Text;
using Behaviours.Helper;

namespace Behaviours.Network.Codec
{
    public class JsonCodec:ICodec
    {
        public byte[] Encode(object obj)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(obj).ToByteArray();
        }

        public object Decode(byte[] bytes)
        {
            string s = Encoding.Default.GetString(bytes);
            return Newtonsoft.Json.JsonConvert.DeserializeObject(s);
        }
    }
}